
package com.flowmodule.servlet;
import com.flowmodule.bean.TbFlowNode;
import com.flowmodule.dao.*;
import com.usersmodule.bean.TbUsers;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import util.*;

public class TbFlowNodeServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        int userId=((TbUsers) request.getSession().getAttribute("Users")).getUserId();
        if("add".equals(method)){
        String flowNodeName=request.getParameter("flowNodeName");
            if(new TbFlowNodeDAO().add(new TbFlowNode(flowNodeName,userId))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
            goList(request, response);
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_FlowNode", "FlowNodeId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
            goList(request, response);
        }
        if("edit".equals(method)){
        int flowNodeId=Integer.parseInt(request.getParameter("flowNodeId"));
        String flowNodeName=request.getParameter("flowNodeName");
            if(new TbFlowNodeDAO().edit(new TbFlowNode(flowNodeId,flowNodeName,userId))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
            goList(request, response);
        }
        if ("list".equals(method))goList(request, response);
        if ("listById".equals(method)) {
             request.getSession(true).setAttribute("tbFlowNode",new TbFlowNodeDAO().getTbFlowNodeByFlowNodeId(Integer.parseInt(request.getParameter("flowNodeId"))));
            response.sendRedirect("FlowModule/TbFlowNodeOperate.jsp");
    	}
        if("showadd".equals(method)){
            request.getSession(true).removeAttribute("tbFlowNode");
            response.sendRedirect("FlowModule/TbFlowNodeOperate.jsp");
        }
    }
    public void goList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.getSession(true).setAttribute("tbFlowNodeList",new TbFlowNodeDAO().getTbFlowNodeAll());
        response.sendRedirect("FlowModule/TbFlowNodeList.jsp");
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
